# -*- coding: utf-8 -*-
"""
Created on Tue Apr 29 17:49:55 2014

@author: svyatoslav
"""

import task2
import unittest
from Bio import SeqIO

class TestBiopythonFunctions(unittest.TestCase):

    def setUp(self):
        self.file_name_1 = 'Fake.txt'
        self.file_name_2 = '../hometask-files/2-bio_toolkits/gene1.fasta'
        self.file_name_3 = '../hometask-files/2-bio_toolkits/gene3.gb'
        self.file_name_4 = 'Empty.fasta'
        with open(self.file_name_4, 'w') as emp:
            pass
        self.genome = SeqIO.read(self.file_name_2, 'fasta')
        self.rna = self.genome.seq.transcribe()

    def test_is_non_zero_file_on_non_existing_file(self):
        self.assertFalse(task2.is_non_zero_file(self.file_name_1))

    def test_is_non_zero_file_on_empty_file(self):
        self.assertFalse(task2.is_non_zero_file(self.file_name_4))

    def test_is_non_zero_file_on_non_empty_file(self):
        self.assertTrue(task2.is_non_zero_file(self.file_name_2))
        
    def test_read_genome_fasta_nonemptiness(self):
        self.assertNotEqual(task2.read_genome(self.file_name_2), "")
        
    def test_read_genome_fasta_alphabet(self):
        self.assertEqual(set(task2.read_genome(self.file_name_2)), set('ACGT'))
        
    def test_read_genome_gb_nonemptyness(self):
        self.assertNotEqual(task2.read_genome(self.file_name_3), "")
        
    def test_read_genome_gb_alphabet(self):
        self.assertEqual(set(task2.read_genome(self.file_name_3)), set('ACGT'))
        
    def test_transcribe_genome_nonemptiness(self):
        self.assertIsNotNone(task2.transcribe_genome(self.genome))
        
    def test_transcribe_genome_alphabet(self):
        self.assertEqual(set(task2.transcribe_genome(self.genome)), set('ACGU'))
    
    def test_transcribe_genome_product_equality(self):
        self.assertEqual(str(task2.transcribe_genome(self.genome)), str(self.rna))

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestBiopythonFunctions)
    unittest.TextTestRunner(verbosity=2).run(suite)
